import VueRouter from 'vue-router'
import homeCon from './components/tabbar/HomeContainer.vue'
import ProducCon from './components/tabbar/ProductsContainer.vue'
import ShopCartCon from './components/tabbar/ShopCart.vue'
import UserSettingCon from './components/tabbar/UserSettingContainer.vue'
import LoginCon from './components/account/LoginContainer.vue'
import RegCon  from './components/account/RegisterContainer.vue'
import TypeCon from './components/Common/typeList.vue'
import SgCon from './components/Common/searchGirdList.vue'
import pdetailCon from './components/Common/productDetail.vue'
import store from './store/datastore.js'
var router = new VueRouter({
	routes:[
		{path:'/',redirect:'/index'},
		{path:'/index',component:homeCon,name:'index'},
		{path:'/products',component:ProducCon,name:'products'},
		{path:'/shopcart',component:ShopCartCon,name:'shopcart'},
		{path:'/usersetting',component:UserSettingCon,name:'usersetting'},
		{path:'/login',component:LoginCon,name:'login'},
		{path:'/register',component:RegCon,name:'Reg'},
		{path:'/typeList',component:TypeCon,name:'typeList'},
		{path:'/searchGirdList',component:SgCon,name:'searchGirdList'},
		{path:'/productDetail',component:pdetailCon,name:'productDetail'}
	],
	linkActiveClass:"mui-active"
})

router.beforeEach(function (to, from, next) {
	const nextRoute = ['shopcart','usersetting'];
	if(nextRoute.indexOf(to.name)>= 0){
		//判断是否已登录
		if(!store.isLogin){
			router.push({name:'login'})
		}
	}
	if (to.name === 'login') {
		//已经登录了 进入 Login
		if(store.isLogin)
		router.push({name:'index'})
		store.state.showBottomTab = false;
    }
    next();

});


export default router
